package com.g3.zoosite.service.impl;

import com.g3.zoosite.model.DwRareAnimal;
import com.g3.zoosite.mapper.DwRareAnimalMapper;
import com.g3.zoosite.service.IDwRareAnimalService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 珍奇动物表 服务实现类
 * </p>
 *
 * @author admin
 * @since 2021-09-28
 */
@Slf4j
@Service
public class DwRareAnimalServiceImpl extends ServiceImpl<DwRareAnimalMapper, DwRareAnimal> implements IDwRareAnimalService {

    @Autowired(required = false)
    private DwRareAnimalMapper rareAnimalMapper;

    @Value("${image-server}")
    private String imageServer;

    //查询所有珍奇动物业务逻辑层方法
    @Override
    public List<DwRareAnimal> findRareAnimals() {
        List<DwRareAnimal> rareAnimals = rareAnimalMapper.selectList(null);
        for (int i=0;i<rareAnimals.size();i++){
            DwRareAnimal dwRareAnimal = rareAnimals.get(i);
            //拼接图片服务器和图片路径
            dwRareAnimal.setImagePath(imageServer + dwRareAnimal.getImagePath() );
            log.info("图片服务器图片路径--："+dwRareAnimal.getImagePath());
        }
        return rareAnimals;
    }


    //通过ID查询动物信息
    @Override
    public DwRareAnimal findRareAnimalById(Integer id) {
        DwRareAnimal rareAnimal = rareAnimalMapper.selectById(id);
        //拼接图片服务器和图片路径
        rareAnimal.setImagePath(imageServer+rareAnimal.getImagePath());
        return rareAnimal;
    }
}
